﻿using System;
using System.Collections.Generic;
using System.Data.Objects;
using System.Linq;
using System.Text;
using JML.Model;
using JML.Services.Interfaces;

namespace JML.Services
{
    public class OrganisationService: IOrganisationService
    {

        public List<Organisation> RetrieveAll()
        {
            try
            {
                // the creation of the travelEntities opens the connection 
                // and sets up all the metadata information automatically for you.
                using (JML.Model.JMLEntities entities = new JMLEntities())
                {
                    // set the blogs merge option to no tracking since this is a
                    // service that doesn't need to have change tracking.
                    entities.Organisation.MergeOption = MergeOption.NoTracking;

                    // need to always span in the Person because logically I want to always
                    // have the person with the blog - see how this is serialized in
                    // MyTravelModelExtension.cs
                    var organisations = from b in entities.Organisation
                                select b;
                    return organisations.ToList();
                }
            }
            catch (Exception ex)
            {
                // NOTE: You should do your own exception handling here
                // problems may be connection, metadata, or there problems.
                throw ex;
            }
        }
    }
}
